package com.zzy.service.serviceimpl;

import com.zzy.Pojo.*;
import com.zzy.dao.Shopping;
import com.zzy.service.ShoppingService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Service
@Transactional(isolation = Isolation.READ_COMMITTED)
public class ShoppingServiceImpl implements ShoppingService
{

    @Resource
    Shopping shopping;
    @Resource
    RedisTemplate<Integer,Object> redisTemplate;

    @Override
    public Account getAccount(String accountID) {
        return shopping.getAccount(accountID);
    }

    @Override
    public int addAccount(Chongzhi cz) {
        Account account = shopping.getAccount(cz.getAccountID());
        cz.setTheBalanceOf(account.getTheBalanceOf());
        return shopping.addAccount(cz);
    }

    @Override
    public String getStatus(String id) {
        return shopping.getStatus(id);
    }

    @Override
    public Account getAccountId(String id) {
        return shopping.getAccountId(id);
    }

    @Override
    public String getmoney(String id) {
        return shopping.getmoney(id);
    }

    @Override
    public int updateAccount(Account a,String b) {
        Account account = shopping.getAccount(a.getAccountID());
        return shopping.updateAccount(account,b);
    }

    @Override
    public int updateChongzhi(Chongzhi cz) {
        String getmoney = shopping.getmoney(cz.getRecordId());
        Double aDouble = Double.valueOf(getmoney);
        BigDecimal bigDecimal = BigDecimal.valueOf(aDouble);
        cz.setTheBalanceOf(bigDecimal);
        return shopping.updateChongzhi(cz);
    }

    @Override
    public List<String> getzh() {
        return shopping.getzh();
    }
}
